home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / tcptimer.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  2KB  |  67 lines

  1. /* TCP timeout routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include "global.h"
  6. #include "mbuf.h"
  7. #include "timer.h"
  8. #include "netuser.h"
  9. #include "internet.h"
  10. #include "tcp.h"
  11.  
  12. int tcptimertype;       /* default backoff to binary exponential */
  13. int Tcp_blimit = 31;
  14.  
  15. /* Timer timeout */
  16. void
  17. tcp_timeout(p)
  18. void *p;
  19. {
  20.     register struct tcb *tcb;
  21.  
  22.     tcb = p;
  23.     if(tcb == NULLTCB)
  24.         return;
  25.  
  26.     /* Make sure the timer has stopped (we might have been kicked) */
  27.     stop_timer(&tcb->timer);
  28.  
  29.     switch(tcb->state){
  30.     case TCP_TIME_WAIT:    /* 2MSL timer has expired */
  31.         close_self(tcb,NORMAL);
  32.         break;
  33.     default:        /* Retransmission timer has expired */
  34.         tcb->flags.retran = 1;    /* Indicate > 1  transmission */
  35.         if( !Tcp_retries || tcb->backoff < Tcp_retries) {
  36.             tcb->backoff++;
  37.             tcb->snd.ptr = tcb->snd.una;
  38.             /* Reduce slowstart threshold to half current window */
  39.             tcb->ssthresh = tcb->cwind / 2;
  40.             tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  41.             /* Shrink congestion window to 1 packet */
  42.             tcb->cwind = tcb->mss;
  43.             tcp_output(tcb);
  44.         } else reset_tcp(tcb);
  45.     }
  46. }
  47.  
  48. /* Backoff function - the subject of much research */
  49. int32
  50. backoff(n)
  51. int n;
  52. {
  53.     if(tcptimertype) {    /* Linear */
  54.         if(n >= Tcp_blimit)        /* At backoff limit -- N1BEE */
  55.             n = Tcp_blimit;
  56.         else
  57.             ++n;
  58.         return (int32) n;     /* Linear backoff for sensible values! */
  59.     } else {        /* Binary exponential */
  60.         if(n > min(31,Tcp_blimit))
  61.             n = min(31,Tcp_blimit);
  62.                 /* Prevent truncation to zero */
  63.         return 1L << n;    /* Binary exponential back off */
  64.     }
  65. }
  66.  
  67.